package com.gonsin.gmessage.logic.proxy;

import com.gonsin.gmessage.annotations.GSender;
import com.gonsin.gmessage.logic.GMessage;
import com.gonsin.gmessage.logic.exceptions.GMessageException;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.lang.reflect.Method;
import java.lang.reflect.Type;

/**
 * 发送器的描述
 */
@Getter
@Setter
public class SenderAnnotationsModel {

    /**
     * 发送的内容的第一指令
     */
    private String firstCmd;

    /**
     * 发送的内容的次级指令
     */
    private String subCmd;

    /**
     * 发送的质量
     */
    private int qos;

    /**
     * MQTT v5 新特性
     */
    private boolean share;

    public SenderAnnotationsModel(Type interfaceType, GMessage gMessage, Method method, GSender sender) {
        this.firstCmd = gMessage.firstCmd();
        if(StringUtils.isEmpty(firstCmd)){
            throw new GMessageException("缺少firstCmd参数, 请查看%s", interfaceType.getTypeName());
        }
        this.subCmd = sender.subCmd();
        if(StringUtils.isEmpty(firstCmd)){
            throw new GMessageException("缺少subCmd参数, 请查看%s中的%s", interfaceType.getTypeName(), method.getName());
        }
        this.qos = sender.qos();
        this.share = sender.share();
    }
}
